<?php

namespace App\Admin\Controllers\Commodity;

use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;
use App\Model\Commodity_color;
use Illuminate\Http\Request;

class ApiColorController extends Controller
{
    use ModelForm;

    public function get_color(Request $request)
    {
        $data = $request->input();
        if (empty($data) || empty($data["commodity_id"]))
            return return_array(1, '非法参数');
        $color = new Commodity_color();
        if(!empty($color = $color->get_color_by_commodity_id($data["commodity_id"])))
            return return_array(0,'yes', $color);
        else
            return return_array(1,'未知错误');
    }
    public function add_color(Request $request)
    {
        $data = $request->input();
        if (empty($data) || empty($data["commodity_id"]))
            return return_array(1, '非法参数');

        $data = array(
            'commodity_id' => $data['commodity_id'],
            'commodity_color_name'=>$data['name'],
        );
        $color = new Commodity_color();
        if(!empty($color->add_color($data)))
            return return_array(0,'yes', $color->get_color_by_commodity_id($data["commodity_id"]));
        else
            return return_array(1,'未知错误');
    }
}
